import type { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
import { useUserStore } from '@/stores'
import { storeToRefs } from 'pinia'
export default {
  path: '/courseTask',
  name: 'courseTask',
  meta: {
    title: 'courseTask.title',
    requiresAuth: true,
    roles: ['*'],
    icon: 'Notebook',
    order: 1
  },
  beforeEnter: (
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    next: NavigationGuardNext
  ) => {
    const { userInfo } = storeToRefs(useUserStore())
    if (to.path !== '/courseTask') {
      return next()
    }
    switch (userInfo.value.role) {
      case '*':
        next('/courseTask/teacher/publishTask')
        break
      case 'student':
        next('/courseTask/student/commitTask')
        break
      case 'teacher':
        next('/courseTask/teacher/publishTask')
        break
    }
  },
  children: [
    {
      path: '/courseTask/teacher/publishTask',
      name: 'courseTask-teacher-publishTask',
      component: () => import('@/views/courseTask/teacher/publishTask.vue'),
      meta: {
        title: 'courseTask.teacher.publishTask.title',
        requiresAuth: true,
        roles: ['teacher'],
        icon: 'Notebook',
        order: 0,
        isKeepAlive: true
      }
    },
    {
      path: '/courseTask/teacher/finish',
      name: 'courseTask-teacher-finish',
      component: () => import('@/views/courseTask/teacher/finish.vue'),
      meta: {
        title: 'courseTask.teacher.finish.title',
        requiresAuth: true,
        roles: ['teacher'],
        icon: 'Notebook',
        order: 1,
        isKeepAlive: true
      }
    },
    {
      path: '/courseTask/student/commitTask',
      name: 'courseTask-student-commitTask',
      component: () => import('@/views/courseTask/student/commitTask.vue'),
      meta: {
        title: 'courseTask.student.commitTask.title',
        requiresAuth: true,
        roles: ['student'],
        icon: 'Notebook',
        order: 0,
        isKeepAlive: true
      }
    }
  ]
}
